package com.csg.ses.controller;

import com.csg.ses.common.annotation.LoginToken;
import com.csg.ses.entity.ses.GroupTypeEntity;
import com.csg.ses.entity.ses.NewsInfoEntity;
import com.csg.ses.vo.common.Result;
import com.csg.ses.vo.common.ResultStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.csg.ses.vo.common.IdListVo;
import java.util.List;
import com.csg.ses.service.ses.GroupTypeService;

/**
 * 
 * @author zhanggongrong
 * @date 2021-04-11 11:20:47
 */
@RestController
@RequestMapping("/groupType")
@Api(tags = "接口")
public class GroupTypeController {
    @Autowired
    private GroupTypeService groupTypeService;

    /**
     * 列表
     */
    @ApiOperation(value = "列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "groupType", value = "", dataType = "GroupTypeEntity", paramType = "body"),
        @ApiImplicitParam(name = "current", value = "当前页", required = true ,dataType = "Integer"),
        @ApiImplicitParam(name = "size", value = "每页记录数", required = true ,dataType = "Integer")
    })
    @GetMapping("/list")
    @LoginToken
    public Result<List<GroupTypeEntity>> list(GroupTypeEntity groupType, Long current, Long size) {
        return groupTypeService.retrieve(groupType, current, size);
    }

    @GetMapping("/listAll")
    @LoginToken
    public Result<List<NewsInfoEntity>> list() {
        return groupTypeService.queryAllGroupType();
    }

    /**
     * 删除
     * @param idList
     * @return
     */
    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "idList", value = "ID数组", dataType = "IdListVo", paramType = "body", required = true)
    @DeleteMapping("/del")
    @LoginToken
    public Result<String> del(@RequestBody IdListVo idList) {
        return groupTypeService.del(idList);
    }

    @ApiOperation(value = "根据id查找")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String", required = true)
    @GetMapping("/{id}")
    @LoginToken
    public Result<GroupTypeEntity> getById(@PathVariable String id) {
        return groupTypeService.getById(id);
    }

    /**
     * 保存
     * @param
     * @return
     */
    @ApiOperation(value = "保存")
    @ApiImplicitParam(name = "groupType", value = "", dataType = "GroupTypeEntity", paramType = "body")
    @PostMapping("/save")
    @LoginToken
    public Result<String> save(@RequestBody GroupTypeEntity groupType) {
        boolean result = groupTypeService.save(groupType);
        if (result) {
            return new Result("保存成功！", ResultStatus.SUCCESS);
        } else {
            return new Result("保存失败！", ResultStatus.FAILED);
        }
    }
}